﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SHDQGSWEB.Models
{
    public class AdsRepository
    {
        SHDQGSDBDataContext db = new SHDQGSDBDataContext();
        public IQueryable<Ad> GetHomeAds()
        {
            return from ad in db.Ads
                   where ad.Part == "Home"
                   select ad;
        }
        public Ad GetHomeAd(int adId)
        {
            return db.Ads.Single(ad => ad.AdsId == adId);
        }
        public void Replace(int adId, string path)
        {
            var mAd = db.Ads.Single(ad => ad.AdsId == adId);
            if(mAd == null)
            {
               mAd.Parth = path;
            }
            
            db.SubmitChanges();
        }
        public void InsertAds(Ad ad)
        {
            db.Ads.InsertOnSubmit(ad);
        }
        public void DeleteAds(Ad ad)
        {
            db.Ads.DeleteOnSubmit(ad);
        }
        public void Save()
        {
            db.SubmitChanges();
        }
    }
}